<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>VM Spec  </title>
</head>
<body BGCOLOR=#eeeeff text=#000000 LINK=#0000ff VLINK=#000077 ALINK=#ff0000>
<table width=100%><tr>
<td><a href="VMSpecTOC.doc.html">Contents</a> | <a href="Instructions2.doc8.html">Prev</a> | <a href="Instructions2.doc10.html">Next</a> | <a href="VMSpecIX.fm.html">Index</a></td><td align=right><i><i>The Java<sup><font size=-2>TM</font></sup> Virtual Machine Specification</i></i></td>
</tr></table>


<hr><br>
 
<a href="Instructions2.doc.html">A</a>
<a href="Instructions2.doc1.html">B</a>
<a href="Instructions2.doc2.html">C</a>
<a href="Instructions2.doc3.html">D</a>
<a href="Instructions2.doc4.html">F</a>
<a href="Instructions2.doc5.html">G</a>
<a href="Instructions2.doc6.html">I</a>
<a href="Instructions2.doc7.html">J</a>
<a href="Instructions2.doc8.html">L</a>
<a href="Instructions2.doc9.html">M</a>
<a href="Instructions2.doc10.html">N</a>
<a href="Instructions2.doc11.html">P</a>
<a href="Instructions2.doc12.html">R</a>
<a href="Instructions2.doc13.html">S</a>
<a href="Instructions2.doc14.html">T</a>
<a href="Instructions2.doc15.html">W</a>

<a name="monitorenter"></a>
<hr><h2>monitorenter</h2>
<a name="monitorenter.Operation"></a>
<p><b>Operation</b><br>
<blockquote>Enter monitor for object<a name="69702"></a>
<p><Table Border="1">
</blockquote>

<p><b>Format</b><br>
<blockquote>

<tr><td><a name="69701"></a>
 <i>monitorenter</i>
<td><a name="87568"></a>
 

</Table><br></blockquote><p>
<a name="monitorenter.Forms"></a>
<p><b>Forms</b><br>
<blockquote><a name="69703"></a>
<i>monitorenter</i> = 194 (0xc2)</blockquote><p>
<a name="monitorenter.Operand"></a>
<p><b>Operand Stack</b><br>
<blockquote><a name="69704"></a>
..., <i>objectref</i><em> </em><img src="chars/arrwdbrt.gif"> ... </blockquote><p>
<a name="monitorenter.Description"></a>
<p><b>Description</b><br>
<blockquote><a name="69705"></a>
The <i>objectref</i> must be of type <code>reference</code>.</blockquote><p>
<blockquote><a name="69706"></a>
Each object has a monitor associated with it. The thread that executes <i>monitorenter</i> gains ownership of the monitor associated with <i>objectref</i>. If another thread already owns the monitor associated with <i>objectref</i>, the current thread waits until the object is unlocked, then tries again to gain ownership. If the current thread already owns the monitor associated with <i>objectref</i>, it increments a counter in the monitor indicating the number of times this thread has entered the monitor. If the monitor associated with <i>objectref</i> is not owned by any thread, the current thread becomes the owner of the monitor, setting the entry count of this monitor to 1.</blockquote><p>
<a name="monitorenter.Runtime"></a>
<p><b>Runtime Exception</b><br>
<blockquote><a name="69708"></a>
If <i>objectref</i><em> </em>is <code>null</code>, <i>monitorenter</i> throws a <code>NullPointerException</code>. </blockquote><p>
<a name="monitorenter.Notes"></a>
<p><b>Notes</b><br>
<blockquote><a name="131155"></a>
For detailed information about threads and monitors in the Java virtual machine, see <a href="Threads.doc.html#21293">Chapter 8</a>, <a href="Threads.doc.html#21294">"Threads and Locks."</a></blockquote><p>

<blockquote><a name="131158"></a>
A <i>monitorenter</i> instruction may be used with one or more <i>monitorexit</i> instructions to implement a <code>synchronized</code> statement in the Java programming language. The <i>monitorenter</i> and <i>monitorexit</i> instructions are not used in the implementation of <code>synchronized</code> methods, although they can be used to provide equivalent locking semantics; however, monitor entry on invocation of a <code>synchronized</code> method is handled implicitly by the Java virtual machine's method invocation instructions. See <a href="Compiling.doc.html#6530">Section 7.14</a> for more information on the use of the <i>monitorenter</i> and <i>monitorexit</i> instructions.</blockquote><p>
<blockquote><a name="125548"></a>
The association of a monitor with an object may be managed in various ways that are beyond the scope of this specification. For instance, the monitor may be allocated and deallocated at the same time as the object. Alternatively, it may be dynamically allocated at the time when a thread attempts to gain exclusive access to the object and freed at some later time when no thread remains in the monitor for the object.</blockquote><p>
<blockquote><a name="125547"></a>
The synchronization constructs of the Java programming language require support for operations on monitors besides entry and exit. These include waiting on a monitor (<code>Object.wait</code>) and notifying other threads waiting on a monitor (<code>Object.notifyAll</code> and <code>Object.notify</code>). These operations are supported in the standard package <code>java.lang</code> supplied with the Java virtual machine. No explicit support for these operations appears in the instruction set of the Java virtual machine.</blockquote><p>

<a name="monitorexit"></a>
<hr><h2>monitorexit</h2>
<a name="monitorexit.Operation"></a>
<p><b>Operation</b><br>
<blockquote>Exit monitor for object<a name="69724"></a>
<p><Table Border="1">
</blockquote>

<p><b>Format</b><br>
<blockquote>

<tr><td><a name="69723"></a>
 <i>monitorexit</i>
<td><a name="87568"></a>
 

</Table><br></blockquote><p>
<a name="monitorexit.Forms"></a>
<p><b>Forms</b><br>
<blockquote><a name="69725"></a>
<i>monitorexit</i> = 195 (0xc3)</blockquote><p>
<a name="monitorexit.Operand"></a>
<p><b>Operand Stack</b><br>
<blockquote><a name="69726"></a>
..., <i>objectref</i><em> </em><img src="chars/arrwdbrt.gif"> ... </blockquote><p>
<a name="monitorexit.Description"></a>
<p><b>Description</b><br>
<blockquote><a name="69727"></a>
The <i>objectref</i> must be of type <code>reference</code>.</blockquote><p>
<blockquote><a name="69728"></a>
The current thread should be the owner of the monitor associated with the instance referenced by <i>objectref</i>. The thread decrements the counter indicating the number of times it has entered this monitor. If as a result the value of the counter becomes zero, the current thread releases the monitor. If the monitor associated with <i>objectref</i> becomes free, other threads that are waiting to acquire that monitor are allowed to attempt to do so.</blockquote><p>
<a name="monitorexit.Runtime"></a>
<p><b>Runtime Exceptions</b><br>
<blockquote><a name="69730"></a>
If <i>objectref</i><em> </em>is <code>null</code>, <i>monitorexit</i> throws a <code>NullPointerException</code>. </blockquote><p>
<blockquote><a name="69731"></a>
Otherwise, if the current thread is not the owner of the monitor, <i>monitorexit</i> throws an <code>IllegalMonitorStateException</code>.</blockquote><p>
<blockquote><a name="251458"></a>
Otherwise, if the virtual machine implementation enforces the rules on structured use of locks described in <a href="Threads.doc.html#22500">Section 8.13</a> and if the second of those rules is violated by the execution of this <i>monitorexit</i> instruction, then <i>monitorexit</i> throws an <code>IllegalMonitorStateException</code>.</blockquote><p>
<a name="monitorexit.Notes"></a>
<p><b>Notes</b><br>
<blockquote><a name="131165"></a>
For detailed information about threads and monitors in the Java virtual machine, see <a href="Threads.doc.html#21293">Chapter 8</a>, <a href="Threads.doc.html#21294">"Threads and Locks."</a></blockquote><p>

<blockquote><a name="125629"></a>
One or more <i>monitorexit</i> instructions may be used with a <i>monitorenter</i> instruction to implement a <code>synchronized</code> statement in the Java programming language. The <i>monitorenter</i> and <i>monitorexit</i> instructions are not used in the implementation of <code>synchronized</code> methods, although they can be used to provide equivalent locking semantics.</blockquote><p>
<blockquote><a name="504908"></a>
The Java virtual machine supports exceptions thrown within <code>synchronized</code> methods and <code>synchronized</code> statements differently. Monitor exit on normal <code>synchronized</code> method completion is handled by the Java virtual machine's return instructions. Monitor exit on abrupt <code>synchronized</code> method completion is handled implicitly by the Java virtual machine's <i>athrow</i> instruction. When an exception is thrown from within a <code>synchronized</code> statement, exit from the monitor entered prior to the execution of the <code>synchronized</code> statement is achieved using the Java virtual machine's exception handling mechanism. See <a href="Compiling.doc.html#6530">Section 7.14</a> for more information on the use of the <i>monitorenter</i> and <i>monitorexit</i> instructions.</blockquote><p>

<a name="multianewarray"></a>
<hr><h2>multianewarray</h2>
<a name="multianewarray.Operation"></a>
<p><b>Operation</b><br>
<blockquote><a name="69744"></a>
Create new multidimensional array<p><Table Border="1">
</blockquote>

<p><b>Format</b><br>
<blockquote>

<tr><td><a name="69737"></a>
 <i>multianewarray</i>
<td><a name="87568"></a>
 

<tr><td><a name="69739"></a>
 <i>indexbyte1</i>
<td><a name="87568"></a>
 

<tr><td><a name="69741"></a>
 <i>indexbyte2</i>
<td><a name="87568"></a>
 

<tr><td><a name="69743"></a>
 <i>dimensions</i>
<td><a name="87568"></a>
 

</Table><br></blockquote><p>
<a name="multianewarray.Forms"></a>
<p><b>Forms</b><br>
<blockquote><a name="69745"></a>
<i>multianewarray</i> = 197 (0xc5)</blockquote><p>
<a name="multianewarray.Operand"></a>
<p><b>Operand Stack</b><br>
<blockquote><a name="69746"></a>
...,<em> </em><i>count1</i>, [<i>count2</i>,<em> </em>...]<em> </em><img src="chars/arrwdbrt.gif"> ..., <i>arrayref</i></blockquote><p>
<a name="multianewarray.Description"></a>
<p><b>Description</b><br>
<blockquote><a name="69747"></a>
The <i>dimensions</i> operand is an unsigned byte that must be greater than or equal to 1. It represents the number of dimensions of the array to be created. The operand stack must contain <i>dimensions</i> values. Each such value represents the number of components in a dimension of the array to be created, must be of type <code>int</code>, and must be nonnegative. The <i>count1</i> is the desired length in the first dimension, <i>count2</i> in the second, etc.</blockquote><p>
<blockquote><a name="104839"></a>
All of the <i>count</i> values are popped off the operand stack. The unsigned <i>indexbyte1</i> and <i>indexbyte2</i> are used to construct an index into the runtime constant pool of the current class <a href="Overview.doc.html#17257">(&#167;3.6)</a>, where the value of the index is (<i>indexbyte1</i> << 8) | <i>indexbyte2</i>. The runtime constant pool item at the index must be a symbolic reference to a class, array, or interface type. The named class, array, or interface type is resolved <a href="ConstantPool.doc.html#71636">(&#167;5.4.3.1)</a>. The resulting entry must be an array class type of dimensionality greater than or equal to <i>dimensions</i>.</blockquote><p>

<blockquote><a name="69758"></a>
A new multidimensional array of the array type is allocated from the garbage-collected heap. If any <i>count</i> value is zero, no subsequent dimensions are allocated. The components of the array in the first dimension are initialized to subarrays of the type of the second dimension, and so on. The components of the last allocated dimension of the array are initialized to the default initial value for the type of the components (<a href="Concepts.doc.html#15858">&#167;2.5.1</a>). A <code>reference</code> <i>arrayref</i> to the new array is pushed onto the operand stack. </blockquote><p>
<a name="multianewarray.Linking"></a>
<p><b>Linking Exceptions</b><br>
<blockquote><a name="119072"></a>
During resolution of the symbolic reference to the class, array, or interface type, any of the exceptions documented in <a href="ConstantPool.doc.html#71636">Section 5.4.3.1</a> can be thrown.</blockquote><p>
<blockquote><a name="69765"></a>
Otherwise, if the current class does not have permission to access the element type of the resolved array class, <i>multianewarray</i> throws an <code>IllegalAccessError</code>.</blockquote><p>
<a name="multianewarray.Runtime"></a>
<p><b>Runtime Exception</b><br>
<blockquote><a name="69770"></a>
Otherwise, if any of the <i>dimensions</i> values on the operand stack are less than zero, the <i>multianewarray</i> instruction throws a <code>Negative</code><code>ArraySizeException</code>.</blockquote><p>
<a name="multianewarray.Notes"></a>
<p><b>Notes</b><br>
<blockquote><a name="69772"></a>
It may be more efficient to use <i>newarray</i> or <i>anewarray</i> when creating an array of a single dimension.</blockquote><p>
<blockquote><a name="69773"></a>
The array class referenced via the runtime constant pool may have more dimensions than the <i>dimensions</i> operand of the <i>multianewarray</i> instruction. In that case, only the first <i>dimensions</i> of the dimensions of the array are created.</blockquote><p>


<hr>
<!-- This inserts footnotes--><p>
<a href="VMSpecTOC.doc.html">Contents</a> | <a href="Instructions2.doc8.html">Prev</a> | <a href="Instructions2.doc10.html">Next</a> | <a href="VMSpecIX.fm.html">Index</a>
<p>
<font size="-1"><i>The Java</i><sup><font size=-2>TM</font></sup><i> Virtual Machine Specification </i><br>
<!-- HTML generated by Suzette Pelouch on March 30, 1999 -->
<i><a href="Copyright.doc.html">Copyright &#169 1999 Sun Microsystems, Inc.</a>
All rights reserved</i>
<br>
Please send any comments or corrections to <a href="mailto:jvm@java.sun.com">jvm@java.sun.com</a>
</font>
</body></html>
